﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.mainmenu {
    import flash.events.*;
    import org.robotlegs.core.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.vo.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.components.mainmenu.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.models.world.*;

    public class RoomsTabMediator extends AbstractShopTabMediator implements IMediator {

		[Inject]
        public var userModel:UserModel;
		[Inject]
        public var roomSlotsModel:RoomSlotsModel;
		[Inject]
        public var tutorialModel:TutorialModel;
		[Inject]
        public var worldModel:WorldModel;
		[Inject]
        public var levelModel:LevelModel;

        override public function onRegister():void{
            tabDisplay.category = ShopItemVO.CATEGORY_ROOMS;
            tabDisplay.blockerButton.addEventListener(MouseEvent.CLICK, this.blockerButton_click);
            super.onRegister();
            eventMap.mapListener(eventDispatcher, UserModelEvent.ON_MODEL_CHANGED, this.onUserModelChanged);
        }
        private function blockerButton_click(_arg1:MouseEvent):void{
            dispatch(new Event(EventConstants.BUY_ROOM_SLOT));
        }
        override protected function initWorldComplete(_arg1:Event):void{
            super.initWorldComplete(_arg1);
            this.updateBlockingLayerOverTabs();
        }
        private function onUserModelChanged(_arg1:UserModelEvent):void{
            this.updateBlockingLayerOverTabs();
        }
        override protected function addShopItem(_arg1:ShopItemVO, _arg2:Boolean=false):void{
            var _local3:ShopItemDisplay;
            var _local4 = (_arg1.category == tabDisplay.category);
            if (((_local4) && (_arg1.available))){
                _local3 = createShopItemDisplay(_arg1);
                _local3.addEventListener(MouseEvent.CLICK, item_click);
                if (_arg1.type == GameConstants.TYPE_KIOSK){
                    this.tutorialModel.kioskShopItemPosition = getGlobalItemPosition(_local3);
                };
                if (_arg1.type == GameConstants.TYPE_KINDERGARTEN){
                    this.tutorialModel.kindergartenShopItemPosition = getGlobalItemPosition(_local3);
                };
                if (_arg1.type == GameConstants.TYPE_FOUNTAIN){
                    this.tutorialModel.fountainShopItemPosition = getGlobalItemPosition(_local3);
                };
            };
        }
        private function updateBlockingLayerOverTabs():void{
            tabDisplay.setBlockerLabel(this.getLabelTextBasedOnZoomState(), languageModel.getTextByKey("shop_noslots_buyrooms"));
            if (this.conditionsAreValidToEnableRoomTab()){
                tabDisplay.hideBlockLayer();
            } else {
                tabDisplay.showBlockLayer();
            };
        }
        private function conditionsAreValidToEnableRoomTab():Boolean{
            return ((this.roomSlotsModel.freeSlots > 0));
        }
        private function getLabelTextBasedOnZoomState():String{
            var _local1:int = this.levelModel.getNextLevelWithNewSlot(this.userModel.level).level;
            return (languageModel.getTextByKey("shop_noslots_errormessage_new", {level:_local1}));
        }

    }
}//package net.wooga.pets.views.mainmenu 
